using MicroMsg.Common.Utils;
using MicroMsg.Scene;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class QQMsgVerifyControl : UserControl
	{
		public delegate void dismissWithClickBtn(object sender, int nClickIndex);
		private static QQMsgVerifyControl sQQMsgVerifyControl;
		private ModeDialogHelper mDlgHelper;
		private string mStrImgSid;
		private byte[] mImageBuf;
		private bool mBIsLoaded;
		internal Grid LayoutRoot;
		internal StackPanel panelRoot;
		internal TextBlock txtTitle;
		internal TextBlock txtContent;
		internal Image imgVCode;
		internal Button btnResetImg;
		internal TextBox txtInVcode;
		internal Button btnOk;
		internal Button btnCancel;
		private bool _contentLoaded;
		public event QQMsgVerifyControl.dismissWithClickBtn mBtnClick;
		public QQMsgVerifyControl(bool isEnableBackKeyPress, string imgSid, byte[] imgBuf, QQMsgVerifyControl.dismissWithClickBtn clickHandler = null)
		{
			this.InitializeComponent();
			this.mBtnClick = clickHandler;
			this.mStrImgSid = imgSid;
			this.mImageBuf = imgBuf;
			this.mDlgHelper = new ModeDialogHelper(this, isEnableBackKeyPress, (SolidColorBrush)Application.get_Current().get_Resources().get_Item("NearOpacityBrush1"), false);
			base.add_Loaded(new RoutedEventHandler(this.QQMsgVerifyControl_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.QQMsgVerifyControl_Unloaded));
		}
		private void QQMsgVerifyControl_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.mBIsLoaded)
			{
				return;
			}
			this.mBIsLoaded = true;
			this.ShowVCodeImage();
		}
		private void QQMsgVerifyControl_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void ShowVCodeImage()
		{
			if (this.mImageBuf == null)
			{
				return;
			}
			if (this.mImageBuf != null)
			{
				BitmapImage bitmapImage = new BitmapImage();
				MemoryStream source = new MemoryStream(this.mImageBuf);
				try
				{
					bitmapImage.SetSource(source);
					this.imgVCode.set_Source(bitmapImage);
					return;
				}
				catch (Exception ex)
				{
					string text = ex.ToString();
					Log.smethod_5(base.GetType().ToString(), "bad mImageBuf" + text);
					return;
				}
			}
			Log.smethod_5(base.GetType().ToString(), "null == mImageBuf");
		}
		public static QQMsgVerifyControl Show(bool isEnableBackKeyPress, string imgSid, byte[] imgBuf, QQMsgVerifyControl.dismissWithClickBtn clickHandler = null)
		{
			if (QQMsgVerifyControl.sQQMsgVerifyControl == null)
			{
				QQMsgVerifyControl.sQQMsgVerifyControl = new QQMsgVerifyControl(isEnableBackKeyPress, imgSid, imgBuf, clickHandler);
			}
			QQMsgVerifyControl.sQQMsgVerifyControl.mDlgHelper.Show();
			return QQMsgVerifyControl.sQQMsgVerifyControl;
		}
		public static QQMsgVerifyControl Refresh(string imgSid, byte[] imgBuf)
		{
			if (QQMsgVerifyControl.sQQMsgVerifyControl == null)
			{
				return null;
			}
			QQMsgVerifyControl.sQQMsgVerifyControl.mStrImgSid = imgSid;
			QQMsgVerifyControl.sQQMsgVerifyControl.mImageBuf = imgBuf;
			QQMsgVerifyControl.sQQMsgVerifyControl.ShowVCodeImage();
			QQMsgVerifyControl.sQQMsgVerifyControl.mDlgHelper.Show();
			return QQMsgVerifyControl.sQQMsgVerifyControl;
		}
		public static bool IsShow()
		{
			return QQMsgVerifyControl.sQQMsgVerifyControl != null && QQMsgVerifyControl.sQQMsgVerifyControl.mDlgHelper.IsShow();
		}
		private void btnResetImg_Click(object sender, RoutedEventArgs e)
		{
			ServiceCenter.sceneBindQQ.doSceneRefetchVerifyImgForBindQQ();
		}
		private void btnOk_Click(object sender, RoutedEventArgs e)
		{
			if (string.IsNullOrEmpty(this.txtInVcode.get_Text()))
			{
				return;
			}
			if (this.mBtnClick != null)
			{
				this.mBtnClick(this, 0);
			}
			this.mDlgHelper.Hide(null);
		}
		private void btnCancel_Click(object sender, RoutedEventArgs e)
		{
			if (this.mBtnClick != null)
			{
				this.mBtnClick(this, 1);
			}
			this.mDlgHelper.Hide(null);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Util/QQMsgVerifyControl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelRoot = (StackPanel)base.FindName("panelRoot");
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.txtContent = (TextBlock)base.FindName("txtContent");
			this.imgVCode = (Image)base.FindName("imgVCode");
			this.btnResetImg = (Button)base.FindName("btnResetImg");
			this.txtInVcode = (TextBox)base.FindName("txtInVcode");
			this.btnOk = (Button)base.FindName("btnOk");
			this.btnCancel = (Button)base.FindName("btnCancel");
		}
	}
}
